package com.lzy.pattern.iterator.jdk;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @ClassName: StudentList
 * @Description: TODO
 * @Author: LiuZy
 * @Date: 2022/5/1 20:05
 * @Version: 1.0
 */
public class StudentList<Student> implements Iterable<Student>{

    private List<Student> list;
    StudentList(){
        this.list = new ArrayList<>();
    }

    @Override
    public Iterator<Student> iterator() {
        return new Itr();
    }

    private class Itr implements Iterator<Student>{
        int cursor;

        Itr(){}

        @Override
        public boolean hasNext() {
            return cursor != list.size();
        }

        @Override
        public Student next() {
            Student student = list.get(cursor);
            cursor++;
            return student;
        }
    }


    public boolean add(Student student) {
        list.add(student);
        return true;
    }
}